@extends('layouts.back_stage')
@section('content')
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/clothInfo.css?v=1.0.2">
    <style>
        /*面辅料采购单位换算弹框*/
        .unit{width:330px;height:355px;background:#fff;position:absolute;top:25%;left:30%;-moz-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;z-index:20000;-moz-user-select: none; -webkit-user-select: none;}
        .unit_header{width:100%;height:50px;padding:15px;border-bottom:1px solid #e5e5e5;cursor: move;position: relative;}
        .shutC{float:right;font-size:21px;font-weight:700;line-height:1;color:#ccc;text-shadow:0 1px 0 #fff;opacity:2;cursor:pointer;outline:none;background:#fff;border:0;}
        .shutC:hover{color:red;}
        .unit_center{padding:15px 40px;}
        .unit_center .unit_inp{width:250px;height:30px;padding-left:6px;background:#fff;border:1px solid #ccc;}
        .unit_bottom{padding:15px 40px;}
        .unit_bottom .unit_btn{width:54px;height:30px;float:right;outline:none;border:0;background:#27c24c;color:#fff;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;}
    </style>
    <div class="container">
        <div class="lining-btn">
            <h3 style="float:left;">面辅料档案</h3>
            <a class="lining-a lining-a1" href="javascript:;" style="background:#27c24c;">面辅料采购单位换算</a>
            <a class="lining-a" href="/admin/ingred_data">辅料资料</a>
            <a class="lining-a" href="/admin/fabric_data">面料资料</a>
            <a class="lining-a lining-a2" href="/admin/fabric_color_define">面料色卡号定义</a>
            <a class="lining-a" href="/admin/cloth_info">面辅料类型</a>
        </div>
        <ul class="lining-ul">
            {{--面辅料采购单位换算--}}
            <li id="conver" class="lining-li">
                <div class="fabric-choose" style="width: 50%;">
                    <span>共<span class="in_count info_sum">{{$infos_count}}</span>条信息</span>
                    <a class="btn bt_a btn-primary" href="javascript:;" onclick="addUnit()">添加</a>
                </div>
                <div class="conversion_tab">
                    <table class="conversion" border="1" cellspacing="0" cellpadding="0">
                        <tr></td><td>类型</td><td>采购单据</td><td>BOM使用单位</td><td>采购单位换算BOM单位量</td><td>操作</td></tr>
                        @if(count($infos)>0)
                            @foreach ($infos as $k=>$v)
                                <tr class="tr{{$v->id}}">
                                    @if($v->type==0)
                                    <td class="tdType" abc="0">面料</td>
                                    @else
                                    <td class="tdType" abc="1">辅料</td>
                                    @endif
                                    <td class="tdUnit">{{$v->purchase_data}}</td>
                                    <td class="tdBom">{{$v->bom_unit}}</td>
                                    <td class="tdNum">{{$v->purchase_bom_unit}}</td>
                                    <td>
                                        <a href="javascript:;" onclick="editUnit({{$v->id}})">修改</a>
                                        <a href="javascript:;" onclick="delUnit({{$v->id}})">删除</a>
                                    </td>
                                </tr>
                            @endforeach
                        @endif
                    </table>
                    <span style="float:right;margin-top:30px;"><div style="float: right;margin:20px 0;"><button class="btn btn-info" onclick="returnPage()" style="float:right;">跳转</button><input type="text" class="form-control returnPage" style="width:6rem;float: right;margin:0 5px;"></div>{{$infos->links()}}</span>
                </div>
            </li>
        </ul>
    </div>
    {{--遮罩层--}}
    <div class="mask" style="display:none;"></div>
    {{--面辅料采购单位换算弹框--}}
    <div class="unit" style="display:none;">
        <div class="unit_header">
            <span>添加信息</span>
            <button class="shutC">×</button>
        </div>
        <div class="unit_center">
            <select class="unit_inp unit1">
                <option value="">请选择类型</option>
                <option value="0">面料</option>
                <option value="1">辅料</option>
            </select>
        </div>
        <div class="unit_center">
            <input class="unit_inp unit2" maxlength="10" type="text" autocomplete="off" autocorrect="off" placeholder="采购单据(必)" />
        </div>
        <div class="unit_center">
            <input class="unit_inp unit3" maxlength="10" type="text" autocomplete="off" autocorrect="off" placeholder="BOM使用单位(必)" />
        </div>
        <div class="unit_center">
            <input class="unit_inp unit4" maxlength="10" type="text" autocomplete="off" autocorrect="off" placeholder="采购单位换算BOM单位量(必)" />
        </div>
        <div class="unit_bottom">
            <button class="unit_btn">确定</button>
        </div>
    </div>
    <script>
        /*面辅料采购单位js*/
        $(".unit2").bind("input","onpropertychange",function() {
            $(".unit3").val($(".unit2").val());
        });
        /*点击添加按钮*/
        function addUnit(){
            $(".unit_btn").addClass("unitSure1").removeClass("unitSure2");
            $(".unit2").val("");
            $(".unit3").val("");
            $(".unit4").val("");
            $(".unit").show();
            $(".mask").show();
        }
        //点击确定按钮
        $(document).on("click",".unitSure1",function(){
            var unit1=$(".unit1").val();
            var unit2=$(".unit2").val();
            var unit3=$(".unit3").val();
            var unit4=$(".unit4").val();
            if(unit1==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请选择类型");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            if(unit2==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请填写采购单据");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            if(unit3==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请填BOM使用单位");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $(".unit").hide();
            $(".mask").hide();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                url:'/admin/farbic_unit_add',
                type:'post',
                data:{
                    type: unit1,
                    purchase_data:unit2,
                    bom_unit:unit3,
                    purchase_bom_unit:unit4,
                    status:0
                },
                dataType:'json',
                success:function (data) {
                    if(data.success == true){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("添加成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        });
        //点击关闭按钮
        $(".shutC").click(function(){
            $(".unit").hide();
            $(".mask").hide();
        });
        //删除
        function delUnit(id){
            $(".oText").text("确定要删除吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr("abc",id);
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','DelUnit');
        }
        /*点确定*/
        $(document).on('click','#DelUnit',function(){
            $(".oMask").hide();
            $(".oAnim").hide();
            var id=$(this).attr("abc");
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/admin/farbic_unit_add',
                data:{
                    id:id,
                    status:-1
                },
                dataType:'json',
                success:function (data) {
                    if(data.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("删除成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
        //修改
        function editUnit(id){
            $(".unit_btn").addClass("unitSure2").removeClass("unitSure1");
            var m=$('.tr'+id).children(".tdType").attr("abc");
            $(".unit1 option[value='"+m+"']").attr("selected","selected");
            $(".unit2").val( $('.tr'+id).children(".tdUnit").text() );
            $(".unit3").val( $('.tr'+id).children(".tdBom").text() );
            $(".unit4").val( $('.tr'+id).children(".tdNum").text() );
            $(".unit").show();
            $(".mask").show();
            $(".unitSure2").attr("def",id);
        }
        $(document).on("click",".unitSure2",function(){
            var unt1=$(".unit1").val();
            var unt2=$(".unit2").val();
            var unt3=$(".unit3").val();
            var unt4=$(".unit4").val();
            var id=$(this).attr("def");
            if(unt1==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请选择类型");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            if(unt2==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请填写采购单据");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            if(unt3==""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请填BOM使用单位");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $(".unit").hide();
            $(".mask").hide();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/admin/farbic_unit_add',
                data:{
                    type: unt1,
                    purchase_data:unt2,
                    bom_unit:unt3,
                    purchase_bom_unit:unt4,
                    id: id,
                    status:1
                },
                dataType:'json',
                success:function (data) {
                    if(data.success){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("修改成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
    </script>
@endsection
